package com.bupt.liutong.admin.sch.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.core.base.BaseAction;
import com.bupt.liutong.admin.sch.bo.AlbumBo;
import com.bupt.liutong.admin.sch.bo.AlbumPhotoBo;
import com.bupt.liutong.admin.sch.form.AlbumForm;
import com.bupt.liutong.admin.sch.form.AlbumPhotoForm;
import com.bupt.liutong.util.BeanUtils;

public class AlbumPhotoAction extends BaseAction {
	
	private AlbumPhotoBo albumPhotoBo;
	private AlbumBo albumBo;

	public ActionForward getAlbumPhotosByPage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		AlbumPhotoForm albumPhotoForm = (AlbumPhotoForm) form;
		albumPhotoForm.setPageSize(18);
		request.setAttribute("albumPhotoFormList", albumPhotoBo.getAlbumPhotosByPage(albumPhotoForm, request));
		AlbumForm albumForm = albumBo.getAlbumById(albumPhotoForm.getAlbumId());
		request.setAttribute("albumName", albumForm.getName());
		putPageInfo(request, albumPhotoForm);
		return mapping.findForward("getAlbumPhotosByPageSuccess");
	}

	public ActionForward insertAlbumPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		return mapping.findForward("insertAlbumPhotoSuccess");
	}

	public ActionForward insertAlbumPhotoDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumPhotoForm albumPhotoForm = (AlbumPhotoForm) form;
		albumPhotoBo.insertPhoto(albumPhotoForm, request);
		String path = mapping.findForward("insertAlbumPhotoDoSuccess").getPath() + "&albumId=" + albumPhotoForm.getAlbumId();
		return new ActionForward(path, true);
	}

	public ActionForward updateAlbumPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumPhotoForm albumPhotoForm = (AlbumPhotoForm) form;
		BeanUtils.copyProperties(albumPhotoForm, albumPhotoBo.getAlbumPhotoById(albumPhotoForm));
		return mapping.findForward("updateAlbumPhotoSuccess");
	}

	public ActionForward updateAlbumPhotoDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumPhotoForm albumPhotoForm = (AlbumPhotoForm) form;
		albumPhotoBo.updateAlbumPhoto(albumPhotoForm);
		String path = mapping.findForward("updateAlbumPhotoDoSuccess").getPath() + "&albumId=" + albumPhotoForm.getAlbumId();
		return new ActionForward(path, true);
	}

	public ActionForward deleteAlbumPhotos(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumPhotoForm albumPhotoForm = (AlbumPhotoForm) form;
		String[] ids = request.getParameterValues("id");
		albumPhotoBo.deleteAlbumPhotos(ids, request);
		String path = mapping.findForward("deleteAlbumPhotosSuccess").getPath() + "&albumId=" + albumPhotoForm.getAlbumId();
		return new ActionForward(path, true);
	}

	public void setAlbumPhotoBo(AlbumPhotoBo albumPhotoBo) {
		this.albumPhotoBo = albumPhotoBo;
	}

	public void setAlbumBo(AlbumBo albumBo) {
		this.albumBo = albumBo;
	}
}
